/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.insurance.cis.connection;

import com.insurance.cis.utils.Utils;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TruongLQ
 */
public class CisConnection {
    
    private static final CisConnection INSTANCE = new CisConnection();
    
    public Connection getSqlConnection() throws SQLException{
        final JdbcConfig configuration = Utils.loadJdbcConfig();
        return getSqlConnection(configuration);
    }
    
    public Connection getSqlConnection(final JdbcConfig configuration) throws SQLException{
        java.sql.Connection connection=null;
        try {
            Class.forName(configuration.driverClass);
            String url = configuration.buildUrl();
            connection = java.sql.DriverManager.getConnection(url, 
                    configuration.username, configuration.password);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(CisConnection.class.getName()).log(Level.SEVERE, null, ex);
        } 
        return connection;
    }
    
    public static CisConnection getInstance() {
        return INSTANCE;
    }
}
